/**
 */
package moore.impl;

import moore.Input;
import moore.MoorePackage;
import moore.conditionState;
import moore.signalValue;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Input</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link moore.impl.InputImpl#getValue <em>Value</em>}</li>
 *   <li>{@link moore.impl.InputImpl#getCheckedIn <em>Checked In</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class InputImpl extends AbstractElementImpl implements Input {
	/**
	 * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValue()
	 * @generated
	 * @ordered
	 */
	protected static final signalValue VALUE_EDEFAULT = signalValue.HIGH;

	/**
	 * The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValue()
	 * @generated
	 * @ordered
	 */
	protected signalValue value = VALUE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getCheckedIn() <em>Checked In</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCheckedIn()
	 * @generated
	 * @ordered
	 */
	protected conditionState checkedIn;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected InputImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MoorePackage.Literals.INPUT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public signalValue getValue() {
		return value;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setValue(signalValue newValue) {
		signalValue oldValue = value;
		value = newValue == null ? VALUE_EDEFAULT : newValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MoorePackage.INPUT__VALUE, oldValue, value));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public conditionState getCheckedIn() {
		if (checkedIn != null && checkedIn.eIsProxy()) {
			InternalEObject oldCheckedIn = (InternalEObject)checkedIn;
			checkedIn = (conditionState)eResolveProxy(oldCheckedIn);
			if (checkedIn != oldCheckedIn) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MoorePackage.INPUT__CHECKED_IN, oldCheckedIn, checkedIn));
			}
		}
		return checkedIn;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public conditionState basicGetCheckedIn() {
		return checkedIn;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCheckedIn(conditionState newCheckedIn, NotificationChain msgs) {
		conditionState oldCheckedIn = checkedIn;
		checkedIn = newCheckedIn;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MoorePackage.INPUT__CHECKED_IN, oldCheckedIn, newCheckedIn);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCheckedIn(conditionState newCheckedIn) {
		if (newCheckedIn != checkedIn) {
			NotificationChain msgs = null;
			if (checkedIn != null)
				msgs = ((InternalEObject)checkedIn).eInverseRemove(this, MoorePackage.CONDITION_STATE__INPUT_SIGNAL, conditionState.class, msgs);
			if (newCheckedIn != null)
				msgs = ((InternalEObject)newCheckedIn).eInverseAdd(this, MoorePackage.CONDITION_STATE__INPUT_SIGNAL, conditionState.class, msgs);
			msgs = basicSetCheckedIn(newCheckedIn, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MoorePackage.INPUT__CHECKED_IN, newCheckedIn, newCheckedIn));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MoorePackage.INPUT__CHECKED_IN:
				if (checkedIn != null)
					msgs = ((InternalEObject)checkedIn).eInverseRemove(this, MoorePackage.CONDITION_STATE__INPUT_SIGNAL, conditionState.class, msgs);
				return basicSetCheckedIn((conditionState)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MoorePackage.INPUT__CHECKED_IN:
				return basicSetCheckedIn(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MoorePackage.INPUT__VALUE:
				return getValue();
			case MoorePackage.INPUT__CHECKED_IN:
				if (resolve) return getCheckedIn();
				return basicGetCheckedIn();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MoorePackage.INPUT__VALUE:
				setValue((signalValue)newValue);
				return;
			case MoorePackage.INPUT__CHECKED_IN:
				setCheckedIn((conditionState)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MoorePackage.INPUT__VALUE:
				setValue(VALUE_EDEFAULT);
				return;
			case MoorePackage.INPUT__CHECKED_IN:
				setCheckedIn((conditionState)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MoorePackage.INPUT__VALUE:
				return value != VALUE_EDEFAULT;
			case MoorePackage.INPUT__CHECKED_IN:
				return checkedIn != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (value: ");
		result.append(value);
		result.append(')');
		return result.toString();
	}

} //InputImpl
